<template>
    <div>
        <h1>科室列表</h1>
        <a href="/">主页</a>
        <br>
        <a href="/radd">科室新增</a>
        <br>
        <a href="https://localhost:7173/api/RoomKs/Exlsx">导出</a>
        科室名称<input type="text" v-model="list.name">
        创建日期:<input type="date" v-model="list.mintime">-<input type="date" v-model="list.maxtime">
        <input type="button" value="查询" @click="cx">
        <input type="button" value="重置" @click="cz">
            <table class="table">
                <thead>
                    <tr>
                        <td>科室名称</td>
                        <td>科室人数</td>
                        <td>科室描述</td>
                        <td>创建时间</td>
                        <td>操作</td>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="d in data">
                        <td>{{d.rname}}</td>
                        <td>{{d.rnum}}</td>
                        <td>{{d.rms}}</td>
                        <td>{{moment(d.rtime).format("yyyy-MM-DD HH:mm:ss") }}</td>
                        <td>
                            <input type="button" value="删除" @click="sc(d.rid)">
                            <input type="button" value="编辑" @click="update(d.rid)">
                        </td>
                    </tr>
                </tbody>
            </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import {ref,onMounted} from 'vue'
import {useRouter,useRoute} from 'vue-router'
import moment from 'moment'
const router=useRouter();
const route=useRoute();
const data=ref([{
    "rid": 1,
    "rname": "string",
    "rnum": 0,
    "rms": "string",
    "rtime": "2025-05-19T10:53:45.9953104",
    "isDelete": false
}])
const list=ref({
    name:"",
    mintime:"",
    maxtime:""
})
onMounted(() => {
    show()
})
const show=()=>{
    axios.get("/api/RoomKs/GetRoomKs",{params:list.value}).then(res=>{
        data.value=res.data
    })
}
const cx=()=>{
    show();
}
const cz=()=>{
    list.value.name=""
    list.value.mintime=""
    list.value.maxtime=""
    
}
const sc=(val:any)=>{
    if(confirm("确认删除吗")){
        axios.delete("/api/RoomKs/DeleteRoomKs",{params:{rid:val}}).then(res=>{
        if(res.data>0){
            alert("删除成功")
            show()
        }else{
            alert("删除失败")
            return
        }
    })
    }
    
}
const update=(val:any)=>{
    router.push({path:"/rupdate",query:{rid:val}})
}
</script>

<style scoped>

</style>